package com.py.custom.business.demo.core.mapstruct;

import com.py.custom.business.demo.core.service.model.StudentDTO;
import com.py.custom.business.demo.core.service.model.TemplateDTO;
import com.py.custom.business.demo.protocol.dto.MessageTaskDTO;
import com.py.custom.business.demo.protocol.request.*;
import com.py.custom.business.demo.protocol.vo.StudentVO;
import com.py.custom.business.demo.protocol.vo.TemplateVO;
import com.py.custom.data.entity.demo.Record;
import com.py.custom.data.entity.demo.Student;
import com.py.custom.data.entity.demo.Template;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

/**
 * description： 对象转换工具类
 */
@Mapper(componentModel = "spring")
public interface BeanConvertUtils {

    /**
     * student 转换为 StudentDTO
     *
     * @param student
     * @return
     */
    StudentDTO student2Dto(Student student);

    /**
     * student集合 转换为 StudentDTO集合
     *
     * @param studentList
     * @return
     */
    List<StudentDTO> student2DtoList(List<Student> studentList);


    /**
     * StudentDTO 转换为 StudentVO
     *
     * @param student
     * @return
     */
    @Mapping(target = "createTime", source = "createTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    @Mapping(target = "updateTime", source = "updateTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    StudentVO studentDto2Vo(StudentDTO student);

    /**
     * StudentDTO集合 转换为 StudentVO集合
     *
     * @param studentDtoList
     * @return
     */
    List<StudentVO> studentDto2VoList(List<StudentDTO> studentDtoList);

    /**
     * StudentVO 转换为 Student
     *
     * @param request
     * @return
     */
    Student studentReqCon(StudentRequest request);

    /**
     * TemplateDTO 转换为 TemplateVO
     *
     * @param templateDto
     * @return
     */
    TemplateVO templateDto2Vo(TemplateDTO templateDto);

    /**
     * TemplateDTO集合 转换为 TemplateVO集合
     *
     * @param templateDtoList
     * @return
     */
    List<TemplateVO> templateDto2VoList(List<TemplateDTO> templateDtoList);

    /**
     * Template 转换为 TemplateDTO
     *
     * @param template
     * @return
     */
    TemplateDTO template2Dto(Template template);

    List<TemplateDTO> template2DtoList(List<Template> template);

    Template addTemplateReqCon(AddTemplateRequest request);

    Template updateTemplateReqCon(UpdateTemplateRequest request);

    Template delTemplateReqCon(DelTemplateRequest request);

    @Mappings(
            value = {
                    @Mapping(target = "createTime", ignore = true),
                    @Mapping(target = "updateTime", ignore = true),
                    @Mapping(target = "delFlag", ignore = true)
            }
    )
    Record template2Record(MessageRequest request, Integer status, String content, String failMsg);

    @Mappings(
            value = {
                    @Mapping(target = "message", source = "content")
            }
    )
    MessageTaskDTO message2Dto(String content, MessageRequest request);
}
